package integerCount;

import java.util.Scanner;
import java.util.HashMap;
import java.util.Map;

public class IntegerCount {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        HashMap<Integer, Integer> countMap = new HashMap<>();

        System.out.println("请输入一组整数，以空格或回车分隔，以任意非整数输入结束：");
        while (scanner.hasNextInt()) {
            int number = scanner.nextInt();
            countMap.put(number, countMap.getOrDefault(number, 0) + 1);
        }

        System.out.println("每个整数出现的次数：");
        for (Map.Entry<Integer, Integer> entry : countMap.entrySet()) {
            System.out.println("整数 " + entry.getKey() + " 出现了 " + entry.getValue() + " 次");
        }

        scanner.close();
    }
}
